/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.srcptit.trainning.giangnd.btvn1;

/**
 *
 * @author GIANG
 */
public class B8 {
    static boolean ngto(int n) {
		if (n < 2)
			return false;
		for (int i = 2; i <= Math.sqrt(n); i++)
			if (n % i == 0)
				return false;
		return true;
	}

	static boolean csngto(int n) {
		while (n != 0) {
			int t = n % 10;
			if (t == 0 || t == 1 || t == 4 || t == 6 || t == 8 || t == 9)
				return false;
			n /= 10;
		}
		return true;
	}

	static boolean kg(int n) {
		int t1, t2;
		while (n != 0) {
			t1 = n % 10;
			n /= 10;
			t2 = n % 10;
			if (t2 > t1)
				return false;
		}
		return true;
	}

	public static void main(String args[]) {
		for (int i = 1000000; i <= 9999999; i++)
			if (ngto(i) && csngto(i) && kg(i))
				System.out.print(i + " ");
	}
}
